/** @ingroup lcd
 * @file lcd.h
 * @brief functions to control the lcd and its backlight
 *
 * @author cameris camerisdump@gmail.com
 */

#ifndef _LCD_H_
#define _LCD_H_

#include <stdint.h>

#define LAYOUT_WIDE 0
#define LAYOUT_PORTRAIT 1

/** @name lcd compile time options
 * @{ */
#define LCD_LAYOUT LAYOUT_WIDE
/**@} */

/** @name lcd hardware settings
 * @{ */
#define LCD_LO_DDR		DDRA
#define LCD_LO_PORT		PORTA
#define LCD_LO_PIN		PINA

#define LCD_HI_DDR		DDRC
#define LCD_HI_PORT		PORTC
#define LCD_HI_PIN		PINC

#define LCD_CMD_DDR		DDRB
#define LCD_CMD_PORT	PORTB
#define LCD_CMD_PIN		PINB
#define LCD_CS			PB4
#define LCD_RS			PB2
#define LCD_RD			PB1
#define LCD_WR			PB0

#define LCD_BL_PIN		PB3

#define LCD_BL_TIMERA	TCCR0A
#define LCD_COM0		COM0A0
#define LCD_COM1		COM0A1
#define LCD_WGM0		WGM00
#define LCD_WGM1		WGM01

#define LCD_BL_TIMERB	TCCR0B
#define LCD_WGM2		WGM02
#define LCD_CS0			CS00
#define LCD_CS1			CS01
#define LCD_CS2			CS02

#define LCD_BL_OCR		OCR0A
/**@} */

#if LCD_LAYOUT == LAYOUT_WIDE
	#define LCD_SIZE_X    320
	#define LCD_SIZE_Y    240
#else
	#define LCD_SIZE_X    240
	#define LCD_SIZE_Y    320
#endif

uint8_t lcd_set_bl(uint8_t index);
uint8_t lcd_set_relative_bl(int8_t d);
void lcd_init_bl(void);
void lcd_write_cmd(uint8_t cmd);
void lcd_write_data(uint16_t dat);
void lcd_set_reg(uint8_t cmd, uint16_t dat);
void lcd_init_ports(void);
void lcd_init(void);
void lcd_set_address(uint16_t x, uint16_t y);
void lcd_set_window(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
#endif
